package com.nowcoder.code.lcof;

import com.algorithm.model.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;

public class JZ78 {


    public ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {

        ArrayList<ArrayList<Integer>> list = new ArrayList<>();
        LinkedList<TreeNode> list0 = new LinkedList<>();
        LinkedList<TreeNode> list1 = new LinkedList<>();

        if (pRoot == null) {
            return list;
        }
        list0.add(pRoot);

        ArrayList lt = new ArrayList();
        while (!list0.isEmpty()) {
            TreeNode treeNode = list0.pollFirst();
            lt.add(treeNode.val);

            if (treeNode.left != null) {
                list1.add(treeNode.left);
            }
            if (treeNode.right != null) {
                list1.add(treeNode.right);
            }
            if (list0.isEmpty()) {
                LinkedList<TreeNode> tmp = list0;
                list0 = list1;
                list1 = tmp;
                list.add(lt);
                lt = new ArrayList();
            }

        }

        return list;
    }


}
